package com.zhuiYun.project.api.dynamicState.controller;

import com.zhuiYun.project.annotation.OptLog;
import com.zhuiYun.project.api.dynamicState.enetity.DynamicStateEntity;
import com.zhuiYun.project.api.dynamicState.service.DynamicStateService;
import com.zhuiYun.project.common.controller.BaseController;
import com.zhuiYun.project.common.errorCode.CommonException;
import com.zhuiYun.project.common.response.CommonConstants;
import com.zhuiYun.project.common.response.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName DynamicStateController
 * @Description TODO
 * @Author mao
 * @Date 2023/4/18 9:28
 **/
@RestController
@CrossOrigin
@Slf4j
@Api(tags = "pc动态图片")
@RequestMapping("/DynamicState")
public class DynamicStateController extends BaseController {

    @Autowired
    DynamicStateService dynamicStateService;
    
    /**
    * @Author mao
    * @Description pc端主页需要更换图片全查
    * @Date 2023/4/25 15:23
    * @Return com.zhuiYun.project.common.response.CommonResult*
    */

    @GetMapping("/DynamicStateAll")
    @ApiOperation(value = "动态图查询")
    @OptLog(modular = "pc动态图片管理",type = CommonConstants.SELECT,describe = "全部图片查询")
    public CommonResult DynamicStateAll() throws CommonException{
        log.info("查询图片");
        return dynamicStateService.getDynamicState();
    }

    /**
    * @Author mao
    * @Description TODO PC端修改图片
    * @Date 2023/4/25 15:25
    * @Return com.zhuiYun.project.common.response.CommonResult
    * @param file
    * @param file1
    * @param file2
    * @param dynamicStateEntity
    */

    @PostMapping("/DynamicStateUpd")
    @ApiOperation(value = "修改图片")
    public CommonResult DynamicStateUpd(MultipartFile file, MultipartFile file1, MultipartFile file2, DynamicStateEntity dynamicStateEntity) throws CommonException{
        int i = dynamicStateService.updateDynamicState(file, file1, file2, dynamicStateEntity);
        log.info("修改图片");
        if (i>0){
            return CommonResult.ok();
        }else {
            return CommonResult.error("添加或修改失败");
        }
    }

}